package cn.hrlly.tao2shou.presenter;

import cn.hrlly.tao2shou.biz.EditCommodityBiz;
import cn.hrlly.tao2shou.biz.EditCommodityBizImpl;
import cn.hrlly.tao2shou.domain.Commodity;
import cn.hrlly.tao2shou.listener.OnEditCommodityListener;
import cn.hrlly.tao2shou.view.view_interface.EditCommodityView;

/**
 * User: gengliang
 * Date: 2016-01-28
 * Time: 13:59
 */

public class EditCommodityPresenterImpl implements OnEditCommodityListener,EditCommodityPresenter{

    private EditCommodityBiz editCommodityBiz;
    private EditCommodityView editCommodityView;

    public EditCommodityPresenterImpl(EditCommodityView editCommodityView){
        this.editCommodityBiz=new EditCommodityBizImpl(this);
        this.editCommodityView=editCommodityView;
    }

    @Override
    public void alterCommodity() {
        Commodity commodity=new Commodity();
        commodity.setCommodityName(editCommodityView.getCommodityName());
        commodity.setCommodityCount(editCommodityView.getCommodityCount());
        commodity.setClassification(editCommodityView.getClassification());
        commodity.setExpectedPrice(editCommodityView.getExpectedPrice());
        commodity.setBarterDescription(editCommodityView.getBarterDescription());
        commodity.setNewDegree(editCommodityView.getNewDegree());
        commodity.setCommodityDescription(editCommodityView.getCommodityDescription());
        commodity.setExpectedTime(editCommodityView.getExpectedTime());
        commodity.setExpectedLocation(editCommodityView.getExpectedLocation());
        commodity.setReleaseId(editCommodityView.getReleaseId());
        editCommodityBiz.alterCommodity(commodity,editCommodityView.getCommodityPhotos());
    }

    @Override
    public void deleteCommodity() {
        Commodity commodity=new Commodity();
        commodity.setReleaseId(editCommodityView.getReleaseId());
        editCommodityBiz.deleteCommodity(commodity);
    }

    @Override
    public void editCommoditySucc(String message) {
        editCommodityView.showMessage(message);
        editCommodityView.finishActivity();
    }

    @Override
    public void editCommoditySucc(int message) {
        editCommodityView.showMessage(message);
        editCommodityView.finishActivity();
    }

    @Override
    public void editCommodityFail(String errorMessage) {
        editCommodityView.showMessage(errorMessage);
    }

    @Override
    public void editCommodityFail(int errorMessage) {
        editCommodityView.showMessage(errorMessage);
    }
}
